<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_educategory extends Controller_Abstract {
	
	/**
	 * 视频分类
	 */
	function actionIndex()
	{
		$this->union_table = educategory::meta();
		$parentlist = educategory::getparentlist($_SESSION['acct']['id']);
	    $this->_view['pidlist']= $parentlist;
	    $this->_context->orderField='weight';
	    $this->_context->orderDirection='desc';
        $this->lists();
	}
	 
	/**
	 * 视频分类设置
	 */
	 
	function actionAdd() {
	    //设置要操作的表单，并设置自动插入方式
	    $this->union_table = educategory::meta ();
	    $handle = new helper_autoinsert ( $this->union_table );
	    $form = new Form_educategory_add ( url ( $this->_context->controller_name . '/' . $this->_context->action_name ) );

	    //这里面会自动将get方式获取的参数传递到表单里面去的
	    $result = $handle->add ( $form, 'id', $_GET );
	    if ($this->_context->isGET ()) {
	        //传递$form值
	        $this->_view ['form'] = $result;
	        $this->_viewname = '../form/add';

	        $parentlist = educategory::getparentlist($_SESSION['acct']['id']);
	        $data=array(0=>'一级分类');
	        $parentlist[0]='一级分类';
	        $res=array_merge($data,$parentlist);
	        $form->element('pid')->value= 0;
	        $form->element('acct_id')->value= $_SESSION['acct']['id'];
	        $form->element('pic')->value= '';
	    } else {
	        //记录日志
	        if(!$_POST['id'])	{
	            Syslog::logs ( '添加视频分类,id :' . $handle->form_database_obj->id );
	        }else{
	            Syslog::logs ( '编辑视频分类,id :' . $handle->form_database_obj->id );
	        }
	         
	        if($handle->status=='success')
	            $this->_context->forwardUrl = url("educategory/index");
	        return call_user_func_array(array($this,$handle->status),array($result));
	    }
	     
	}
	 
	/**
	 * 删除视频分类
	 */
	function actionDel() {
	     Syslog::logs("删除视频分类，ID：".print_r($this->_context->ids,true));
	     $this->union_table = educategory::meta();
	     $this->delete(array('id'=>$this->_context->ids));
	}

	/**
	 * 获取二级分类列表
	 */
	function actionGetclasslist(){
		
		if($this->_context->get('id')){
			$id = intval($this->_context->get('id'));
			$item = educategory::getclasslist($id);
			exit(json_encode($item));
		}else{
			exit();
		}

	}


}


